package com.webchat.rmi.pgc.mall;


import com.webchat.common.bean.APIResponseBean;
import com.webchat.domain.vo.request.mall.MallProductStockOperateReqVO;
import com.webchat.domain.vo.request.mall.MallProductStockQueryReqVO;
import com.webchat.rmi.interceptor.RpcRequestInterceptor;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Map;

@FeignClient(name = "webchat-pgc-service",
        contextId = "mallProductStockClient",
        configuration = RpcRequestInterceptor.class)
public interface MallProductStockClient {


    /**
     * 库存扣减
     *
     * 注：这里需要关注并发场景，”防超卖“
     *
     * @param mallProductStockOperateReq
     * @return
     */
    @PostMapping("/pgc-service/mall/stock/reduce")
    APIResponseBean<Boolean> reduceStock(@RequestBody MallProductStockOperateReqVO mallProductStockOperateReq);

    /**
     * 库存新增
     *
     * @param mallProductStockOperateReq
     * @return
     */
    @PostMapping("/pgc-service/mall/stock/increment")
    APIResponseBean<Boolean> incrementStock(@RequestBody MallProductStockOperateReqVO mallProductStockOperateReq);


    /**
     * 查询单个SKU 库存
     *
     * 上游使用注意事项：剩余库存量可能为null（代表sku不存在）
     *
     * @param skuId
     * @return
     */
    @GetMapping("/pgc-service/mall/stock/get/{spuId}/{skuId}")
    APIResponseBean<Integer> getStock(@PathVariable Long spuId, @PathVariable Long skuId);

    /**
     * 批量查询 SKU 库存
     *
     * 上游使用注意事项：剩余库存量可能为null（代表sku不存在）
     *
     * @param mallProductStockQueryReqVO
     * @return
     */
    @PostMapping("/pgc-service/mall/stock/batchGet")
    APIResponseBean<Map<Long, Integer>> batchGetStock(@RequestBody MallProductStockQueryReqVO mallProductStockQueryReqVO);
}
